home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / bash / bash-108 / bash-108.zoo / lib+ / lib-plus.c.orig < prev    next >
Encoding:
Text File  |  1991-08-14  |  4.1 KB  |  219 lines

  1. /** 
  2.  ** (sjk)++ These routines are a bunch of fake outs for various eunchs
  3.  **         routines that are not present on the Atari ST
  4.  **/
  5.  
  6. #include <stat.h>
  7. #include <device.h>
  8. #include <stddef.h>
  9. #include <types.h>
  10. #include <errno.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <macros.h>
  14. #include <sys/time.h>
  15. #include <sys/resource.h>
  16. #include "r-res.h"
  17.  
  18.  
  19. /** 
  20.  ** (sjk)++ Set up a 64K initial stack for Bash to nosh on.
  21.  **/
  22.  
  23. extern long _initial_stack;
  24. long _initial_stack = 64 * 1024L;
  25.  
  26. static char default_host[] = " Atari-ST ";
  27.  
  28. int getdtablesize()
  29.   return(_NFILE); 
  30. }
  31.  
  32. char *gethostname()
  33.   char *ptr;
  34.   ptr = (char *)getenv("HOST");
  35.   if ( ptr == (char *)0 ) return(default_host);
  36.      else return(ptr);
  37. }
  38.  
  39. int sigblock(x)
  40. int x;
  41.   return(1); 
  42. }
  43.  
  44. int sigmask()
  45.   return(0); 
  46. }
  47.  
  48. int sigsetmask(x)
  49. int x;
  50.   return(0); 
  51. }
  52.  
  53. /**
  54.  ** (sjk)++ These routines simulate a eunchs pipe() call using the 
  55.  **         plug and play device tools from Jwahar. 
  56.  **         thanx go to : 1. Jwahar Bammi! 2. Edgar Roeder!
  57.  **/
  58.  
  59. static size_t    pipe_size;
  60. static size_t    pipe_allocated = 0;
  61. static long    pipe_reading_pos, pipe_writing_pos;
  62. static char    *pipe_buffer = NULL;
  63. static int    pipe_is_open = 0;
  64.  
  65. static long
  66. pipe_open(const char *name, int flags, unsigned mode)
  67. {
  68.     return(mkdev('P', 0));
  69. }
  70.  
  71. static long
  72. pipe_close(int fd)
  73. {
  74.     if(pipe_is_open) pipe_is_open--;
  75.     return(0);
  76. }
  77.  
  78. static long
  79. pipe_read(int fd, void *buf, long nbytes)
  80. {
  81.     long    new_pos, ret;
  82.  
  83.     new_pos = min(pipe_size, pipe_reading_pos + nbytes);
  84.     ret = new_pos - pipe_reading_pos;
  85.     if(ret) bcopy(pipe_buffer + pipe_reading_pos, buf, ret);
  86.     pipe_reading_pos = new_pos;
  87.     return(ret);
  88. }
  89.  
  90. static long
  91. pipe_write(int fd, void *buf, long nbytes)
  92. {
  93.     long    new_pos, ret;
  94.  
  95.     new_pos = min(pipe_allocated, pipe_writing_pos + nbytes);
  96.     ret = new_pos - pipe_writing_pos;
  97.     if(ret) bcopy(buf, pipe_buffer + pipe_writing_pos, ret);
  98.     pipe_writing_pos = new_pos;
  99.     pipe_size = max(new_pos, pipe_size);
  100.     return(ret);
  101. }
  102.  
  103. static long
  104. pipe_seek(int fd, long where, int how)
  105. {
  106.     if(how == SEEK_CUR) where += pipe_reading_pos;
  107.     else if(how == SEEK_END) where = pipe_size - where;
  108.     where = max(where, 0);
  109.     where = min(where, pipe_size);
  110.     return(pipe_reading_pos = where);
  111. }
  112.  
  113. static int
  114. pipe_fstat(int fd, struct stat *st)
  115. {
  116.     st->st_blksize = 1024;
  117.     st->st_size = pipe_size;
  118.     st->st_blocks = (pipe_size + 1023) / 1024;
  119.     st->st_ino = fd;
  120.     st->st_rdev = fd;
  121.     st->st_mode = S_IFCHR | 0600;
  122.     st->st_attr = 0x80;
  123.     st->st_ino = st->st_rdev = fd;
  124.     st->st_mtime = st->st_ctime = st->st_atime = 
  125.         time((time_t *)0) - 2;
  126.     st->st_nlink = 2;
  127.     st->st_uid = geteuid();
  128.     st->st_gid = getegid();
  129.     return 0;
  130. }
  131.  
  132. #define pipe_ioctl    NULL
  133.  
  134. extern struct _device    *__devices;
  135.  
  136. struct _device    pipe_dev =
  137.     {"PIPE:", "pipe", mkdev('P', 0),
  138.          pipe_open, pipe_close, pipe_read, pipe_write, 
  139.                  pipe_ioctl,NULL };
  140.  
  141. static void
  142. _init_pipes()
  143. {
  144.     struct _device    *dev;
  145.  
  146.     for(dev = __devices; dev; dev = dev->next)
  147.         if(dev->dev == mkdev('P', 0)) return;
  148.     pipe_dev.next = __devices;
  149.     __devices = &pipe_dev;
  150.     pipe_allocated = 8 * 1024L;
  151.     if(!(pipe_buffer = malloc(pipe_allocated))) pipe_allocated = 0;
  152. }
  153.  
  154. static void
  155. _exit_pipes()
  156. {
  157.     return;
  158. }
  159.  
  160. int 
  161. pipe(fildes)
  162. int    fildes[2];
  163. {
  164.     if(pipe_is_open) return -1; /* can't make this pipe */
  165.     _init_pipes();
  166.     pipe_size = pipe_reading_pos = pipe_writing_pos = 0;
  167.     pipe_is_open = 2;
  168.     fildes[0] = fildes[1] = mkdev('P', 0);
  169.     return 0;
  170. }
  171.  
  172.  
  173. /** 
  174.  ** (sjk)++ Some very weak inplimentation of the ulimit functions.
  175.  **/
  176.  
  177. int
  178. getrlimit(int resource, struct rlimit *rlp)
  179. {
  180.     if(!rlp) {
  181.         errno = EFAULT;
  182.         return -1;
  183.     }
  184.     switch(resource) {
  185.           case RLIMIT_CPU :
  186.           case RLIMIT_FSIZE : {
  187.               rlp->rlim_cur = rlp->rlim_max = RLIM_INFINITY;
  188.               break;
  189.           }
  190.           case RLIMIT_DATA :
  191.           case RLIMIT_STACK :
  192.           case RLIMIT_RSS : {
  193.               rlp->rlim_cur = rlp->rlim_max = (int) rlp - sbrk(0);
  194.               break;
  195.           }
  196.           case RLIMIT_CORE : {
  197.               rlp->rlim_cur = rlp->rlim_max = 0;
  198.               break;
  199.           }
  200.     }
  201.     return 0;
  202. }
  203.  
  204. int
  205. setrlimit(int resource, struct rlimit *rlp)
  206. {
  207.     if(!rlp) {
  208.         errno = EFAULT;
  209.         return -1;
  210.     }
  211.     /* setting resource limits is not implemented */
  212.     return 0;
  213. }
  214.